Repository navigation
fix: limit the size of an event read by EventStreamReader - #1604
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The size limit incorrectly counts an initial BOM, and a close failure can hide the exception explaining why the event was rejected.
2 open issues
What changed in this PR
This PR addresses #1597 by bounding the memory used by EventStreamReader when reading Server-Sent Events.
Changes:
- Adds a configurable event-size limit, defaulting to 1 Mi characters, with bounded line reading.
- Rejects oversized events with an
IOExceptionand closes the reader while preserving CRLF, LF, and CR handling. - Adds boundary and rejection tests and documents the behavior in the changelog.
| File | Description |
|---|---|
org.restlet/src/test/java/org/restlet/representation/EventStreamTestCase.java |
Tests size limits, invalid configuration, and nonblocking CR handling. |
org.restlet/src/main/java/org/restlet/representation/EventStreamReader.java |
Adds bounded reads and configurable event-size enforcement. |
changes.md |
Records the new limit and oversized-event behavior. |
Review effort: Balanced
jlouvel
force-pushed
the
fix/sse-reader-event-limit
branch
2 times, most recently
from
November 1, 2026 21:29
2e6877e to
8a06cec
Compare
EventStreamReader read lines with BufferedReader.readLine() and appended data and comment lines until a blank line, so a server could make a client buffer an unbounded line or event in memory. Lines are now read with a bounded reader that keeps the CRLF, LF and CR handling, and the characters of an event's lines are counted. Beyond the maximum event size (1 Mi characters by default, setMaxEventSize), readEvent() throws an IOException and closes the reader. Fixes #1597. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jerome Louvel <[email protected]>
…size failure The optional byte order mark at the start of the stream was counted in the size of the first event before being removed, so an event of exactly the maximum size was rejected. It is now skipped while reading the first line. When closing the reader failed after an event exceeded the maximum size, the close failure replaced the size failure. The size failure is now thrown, with the close failure suppressed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
jlouvel
force-pushed
the
fix/sse-reader-event-limit
branch
from
November 2, 2026 02:07
3c6b0f1 to
ea3cbb5
Compare
|
This was referenced Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Fixes #1597.
Summary
EventStreamReaderread lines withBufferedReader.readLine()and appendeddata:and comment lines until a blank line, so a server could make a client buffer an unbounded line or event in memory.readLine(). As before, a CR returns the line at once and a following LF is skipped on the next read, so a live stream doesn't block on a trailing CR.setMaxEventSize(int).DEFAULT_MAX_EVENT_SIZEis public.readEvent()throws anIOExceptionand closes the reader, rather than truncating the event. Later reads return null.The limit counts all the lines of an event (field names included), not only the data and comment text, which keeps the check simple and strict.
Testing
New cases in
EventStreamTestCase:EventStreamTestCaseandEventStreamConnectorTestCasepass locally (15 tests). The full core suite was not run locally, because the machine was short of memory; CI runs it.🤖 Generated with Claude Code